<?php
namespace Administrator\Controller;

class IndexController extends Control {

    //后台首页
    public function index(){
        echo 2;
        /*
        //如果未登录，则跳转到登录页面
        if(!session('user_id')&&!cookie('user_id')){
            echo "<script>window.location.href='/admin/index/login'</script>";exit;
        }
        $data['title']='找金银网';
        $this->assign("data", $data);
        $this->display();
        */
    }
    //登录页
    public function login(){
        //如果已登录，则跳转到后台首页
        if(session('user_id')||cookie('user_id')){
            echo "<script>window.location.href='/admin/index/'</script>";exit;
        }
        $data['title']='找金银网';
        $this->assign("data", $data);
        $this->display();
    }
    //登录提交
    public function login_post(){
        //提交
        if($_POST['account']!=''&&$_POST['account']!=''){
            $post['account']=addslashes($_POST['account']);
            $post['password']=addslashes(md5($_POST['password']));
            $Model=D("Administrator");
            $Model->post=$post;
            if(!$Model->check_admin()){
                echo "<script>alert('用户名/密码错误，请您重新输入');history.back(-1);</script>";exit;
            }
            //设置session
            session('user_id',1);
            //设置cookie
            if($_POST['remember']==1){
                cookie('user_id','1',3600);
            }
            echo "<script>window.location.href='/admin/index'</script>";exit;
        }
    }
    //退出登录
    public function logout(){
        session('user_id',null);
        cookie('user_id',null);
        echo "<script>window.location.href='/admin/index/login'</script>";exit;
    }
    //关于
    public function about(){
        $data['title']='关于我们 找金银网';
        $this->assign("data", $data);
        $this->display();
    }
}